package com.xb.loan.cashier.biz.main;

import com.xb.loan.log.exception.ErrorCodeManager;
import com.xb.loan.util.SpringHelper;
import com.xb.loan.util.log.DefaultLoggerFacotry;
import com.xb.loan.util.log.LogFormatUtil;
import org.slf4j.Logger;

import java.io.IOException;

/**
 * 启动收银台主函数
 */
public class StartPlatCashierMain {
    private static final Logger logger = DefaultLoggerFacotry.getLogger(StartPlatCashierMain.class);

    private static volatile boolean running = true;
    
    public static void main(String[] args) throws IOException {
        logger.info(LogFormatUtil.getFormatTemplate(new String[]{"method" , "msg"}) ,
                new String[]{"StartPlatCashierMain.main" , "cashier provider start"});
        
        try {
            
            //加载spring配置文件
            SpringHelper.init(new String[] { "classpath:/spring/applicationContext-cashier.xml" });
            
            logger.info(LogFormatUtil.getFormatTemplate(new String[]{"method" , "msg"}) ,
                    new String[]{"StartPlatCashierMain.main" , "SpringHelper.init end"});
            
            //初始化异常定义信息
            ErrorCodeManager.init();
            
            logger.info(LogFormatUtil.getFormatTemplate(new String[]{"method" , "msg"}) ,
                    new String[]{"StartPlatCashierMain.main" , "ErrorCodeManager.init end"});
            
        } catch (Exception e) {
            
            logger.error(e.getMessage(), e);
            running = false;
            System.exit(1);
        }
        
        synchronized (StartPlatCashierMain.class) {
            while (running) {
                try {
                    
                    StartPlatCashierMain.class.wait();
                    
                } catch (Throwable e) {
                    logger.error("", e);
                }
            }
        }
    }
}
